package com.hs.sfzy.controller;

import com.hs.sfzy.entity.Level;
import com.hs.sfzy.service.LevelService;
import com.hs.sfzy.until.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName LevelController
 * @Description TODO
 * @Author wangzhihao
 * @Date 2025年08月12日 21:45
 * @Version 1.0
 */
@RestController
@RequestMapping("Level")
public class LevelController {
    @Autowired
    private LevelService levelService;
@PostMapping
    public R addLevel(@RequestBody Level level){
        int i = levelService.addLevel(level);
        if (i == 0){
            return R.fail();
        }else {
            return R.ok();
        }
    }
    @GetMapping("{id}")
    public R getLevel(@PathVariable("id") int id){
        Level level = levelService.getLevel(id);
        return R.ok(level);
    }

    @GetMapping("all")
    public R getAllLevel(){
        return R.ok(levelService.getAllLevel());
    }
}
